﻿#region Using

using System;

#endregion

namespace XNgine.Threading
{
    public class ProgressChangedEventArgs : EventArgs
    {
        public int ProgressOld { get; set; }
        public int ProgressNew { get; set; }
    }

    /// <summary>
    /// Adds progress change notifications to the ThreadedExecutor
    /// </summary>
    public class ThreadedLoader : ThreadedExecutor
    {
        private int _progress;

        public int Progress
        {
            get { return _progress; }
            set
            {
                int? oldProgress = null;
                if (_progress != value)
                    oldProgress = _progress;

                _progress = value;

                if (oldProgress != null && ProgressChanged != null)
                    ProgressChanged(this, new ProgressChangedEventArgs {ProgressNew = value, ProgressOld = _progress});
            }
        }

        public event EventHandler<ProgressChangedEventArgs> ProgressChanged;

        private int _max = 100;

        public int Max
        {
            get { return _max; }
            set { _max = value; }
        }

        public float PercentsComplete
        {
            get { return (_progress/Max)*100; }
        }

        public ThreadedLoader(ExecutionMethod exec) : base(exec)
        {
        }
    }
}